﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TestSkypeAlert
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string connStr = "SERVER=10.1.10.120;DATABASE=Voice1900; UID=gianghm;PWD=gianghm15o6";
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtMessage.Text))
                return;
            try
            {
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = string.Format(
                        @"INSERT INTO [Voice1900].[SAMIS].[Warning]([WarningMSG],[timeInsert])
                        VALUES(@msg,@date_time)");
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@msg", txtMessage.Text.Trim());
                        cmd.Parameters.AddWithValue("@date_time", DateTime.Now);
                        cmd.ExecuteNonQuery();
                    }
                }
                MessageBox.Show("Send Message Success!");
                txtMessage.Text = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
